<script> 
window.tms = []; 
window.day = []; 
window.hour = []; 
window.minute = []; 
window.second = []; 
</script>
<?php $index = 0;?>
<?php foreach($this->items as $item):?>
<li>
    <div class="prd simg"><img src="<?php echo MY_URL?>/<?php echo $item['cut_url'];?>"></div>
    <div class="prd spname"><a href="<?php echo $this->url($item['itemid']);?>"><?php echo $item['subject'];?></a></div>
    <div class="prd sprice"><a class="sprice spbg f-blk"><?php if($item['is_suit']==1):?><strong>Team-buying Discount</strong><?php else:?>Price <span class="delete">$<?php echo $item['m_org_price'];?></span> <strong>$<?php echo $item['max_price'];?></strong><?php endif;?></a></div>
    <div><a class="f-blk pboxbar spbg" href="<?php echo $this->url($item['itemid']);?>" title="<?php echo $item['subject'];?>">&nbsp;</a></div>
	<div class="prd sprice"><span class="f1" ><span id="h<?php echo $index;?>" style="font-weight: bold">0</span> <span>h </span><span id="m<?php echo $index;?>" 
style="font-weight: bold">0</span> <span>m </span><span id="s<?php echo $index;?>" style="font-weight: bold"> 
0</span> <span>s</span></span></div>
<script> 
window.tms[tms.length] = "<?php echo $item['endTime'];?>"; 
window.day[day.length] = "d<?php echo $index;?>"; 
window.hour[hour.length] = "h<?php echo $index;?>"; 
window.minute[minute.length] = "m<?php echo $index;?>"; 
window.second[second.length] = "s<?php echo $index;?>"; 
</script> 
</li>
<?php $index++;?>
<?php endforeach;?>
<li>
	<?php if($this->wheneverItemCount>0):?>
	<div class="prd simg"><img src="<?php echo MY_URL?>/images/mlm/clickmore.jpg"></div>
	<div class="prd moreitem"><span><?php echo $this->wheneverItemCount;?></span> <span>Deal<?php if($this->wheneverItemCount>1):?>s<?php endif;?></span> Available</div>
    <?php else:?>
    <div class="prd simg"><img src="<?php echo MY_URL?>/images/mlm/addmorewhenever.jpg"></div>
    <div class="prd noitem"><span>0</span> Deal Available</div>
    <?php endif;?>
    <div><a class="f-blk pboxbar spbg" href="#" id="addMoreWhenEverItem">&nbsp;</a></div>
    <div style="font-size:10px;padding:2px 0px;"><a href="#howtogetwheneverlucky">(?) Get deals via earning plan</a></div>
</li>

<script>
$(function(){
	$('#addMoreWhenEverItem').click(function(){
	<?php if($this->member_type=="buyer"):?>
	var _prev = $(this).parent().prev();
	if(_prev.hasClass('noitem')){
		$.post(ROOT_PATH+"/flash-showwheneverorder",{},function(data) {
			if($.trim(data)!=''){
				GGSHOP.msgBox.show('Add More Lucky Deals',data,'650','434','277');
				GGSHOP.msgBox.content.css({"left":($(window).width()-459)/2+"px", "top": $(document).scrollTop(), "z-index": 9999999});
				$('#buyBtn').unbind();
				$('#selectMoney').unbind();
				$('#buyBtn').click(function(){
					if(confirm("Confirm to pay "+$('#selectMoney').val()/5+" credits for the new deals?")){
						var _itemCount = $('#selectMoney').val();
						GGSHOP.msgBox.hidden();
						$.post(ROOT_PATH+"/flash-payforwheneveritem",{itemCount:_itemCount},function(data) {
							if(data > 0){ 
								_prev.removeClass('noitem');
								_prev.addClass('moreitem');
								var _spans = _prev.find('span');
								var _count = parseInt($(_spans[0]).html())+parseInt(data);
								_prev.parent().find('img').attr('src','/images/mlm/clickmore.jpg');
								$(_spans[0]).html(_count);
								if(_count>1){
									$(_spans[1]).html('items');
								}
							}else{
								alert('some errors.');
							}
						});	
					}
				});
				$('#selectMoney').change(function(){
					if($(this).val()==-1){
						$(this).val(1);
					}
				});
			}
		});
	}else{
		$.post(ROOT_PATH+"/flash-subtractwheneveritem",{},function(data) {
			if($.trim(data)!=''){
				var _spans = _prev.find('span');
				var _count = parseInt($(_spans[0]).html())-1;
				if(_count <= 0){
					_count = 0;
					_prev.parent().find('img').attr('src','/images/mlm/addmore.jpg');
					_prev.removeClass('moreitem');
					_prev.addClass('noitem');
				}
				$(_spans[0]).html(_count);
				if(_count=1){
					$(_spans[1]).html('item');
				}
				_prev.parent().before(data)
			}
		});
	}
	<?php else:?>
	window.location.href="/auth-login?preurl=%2Fflash-index";
	<?php endif;?>
	return false;
});

window.takeCount = function() { 
	//setTimeout("takeCount()", 1000); 
	
	var tms = window.tms; 
	var day = window.day; 
	var hour = window.hour; 
	var minute = window.minute; 
	var second = window.second; 

	for (var i = 0, j = tms.length; i < j; i++) { 
		tms[i] -= 1; 
		var rest = tms[i]-<?php echo time();?>;
		if(rest >= 0){
			var days = parseInt(rest / 86400);
		    rest = rest - days * 86400;
		    var hours = parseInt(rest / 3600);
		    rest = rest - hours * 3600;
		    var minutes = parseInt(rest / 60);
		    var seconds = rest - minutes * 60;
			
			if (days < 0) 
			days = 0; 
			if (hours < 0) 
			hours = 0; 
			if (minutes < 0) 
			minutes = 0; 
			if (seconds < 0) 
			seconds = 0; 
			$('#'+hour[i]).html(hours); 
			$('#'+minute[i]).html(minutes); 
			$('#'+second[i]).html(seconds); 
		}else{
			$('#'+hour[i]).parent().parent().parent().hide();
		}
	} 
} 
setInterval("takeCount()", 1000); 
});
</script>